package roles

import (
	"xagent/internal/actors"
	"xagent/internal/prompts"
	proto "xagent/proto/v1"
)

// DevOpsEngineer represents a DevOps engineer
type DevOpsEngineer struct {
	*actors.BaseAgent
	templates *prompts.TemplateManager
}

// NewDevOpsEngineer creates a new DevOps engineer
func NewDevOpsEngineer() *DevOpsEngineer {
	baseAgent := actors.NewBaseAgent(
		"devops",
		"Responsible for deployment, infrastructure and operations",
	)
	return &DevOpsEngineer{
		BaseAgent: baseAgent,
		templates: prompts.NewTemplateManager(),
	}
}

// ProcessTask handles DevOps tasks
func (d *DevOpsEngineer) ProcessTask(task *proto.Task) {
	switch task.Name {
	case "Deployment":
		d.handleDeployment(task)
	case "Monitoring":
		d.handleMonitoring(task)
	case "Infrastructure":
		d.handleInfrastructure(task)
	}
}

// handleDeployment handles deployment tasks
func (d *DevOpsEngineer) handleDeployment(task *proto.Task) {
	response := &proto.AgentMessage{
		Id:   task.Id,
		Type: proto.MessageType_MESSAGE_TYPE_RESPONSE,
		Content: &proto.AgentMessage_Message{
			Message: "Deployment completed",
		},
		Metadata: map[string]string{
			"type":   "deployment",
			"status": "completed",
		},
	}

	if parent := d.GetContext().Parent(); parent != nil {
		d.GetContext().Send(parent, response)
	}
}

// handleMonitoring handles monitoring tasks
func (d *DevOpsEngineer) handleMonitoring(task *proto.Task) {
	response := &proto.AgentMessage{
		Id:   task.Id,
		Type: proto.MessageType_MESSAGE_TYPE_RESPONSE,
		Content: &proto.AgentMessage_Message{
			Message: "Monitoring setup completed",
		},
		Metadata: map[string]string{
			"type":   "monitoring",
			"status": "completed",
		},
	}

	if parent := d.GetContext().Parent(); parent != nil {
		d.GetContext().Send(parent, response)
	}
}

// handleInfrastructure handles infrastructure tasks
func (d *DevOpsEngineer) handleInfrastructure(task *proto.Task) {
	response := &proto.AgentMessage{
		Id:   task.Id,
		Type: proto.MessageType_MESSAGE_TYPE_RESPONSE,
		Content: &proto.AgentMessage_Message{
			Message: "Infrastructure setup completed",
		},
		Metadata: map[string]string{
			"type":   "infrastructure",
			"status": "completed",
		},
	}

	if parent := d.GetContext().Parent(); parent != nil {
		d.GetContext().Send(parent, response)
	}
}
